<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2024/4/10
 * Time: 12:01
 */

namespace plugin\admin\app\logic\music;


use app\common\lib\Common;
use app\common\lib\Spreadsheet;
use app\common\lib\TencentCos;
use app\model\douyin\CooperateAppidModel;
use plugin\admin\app\common\Constant;
use plugin\admin\app\exception\AdminException;
use plugin\admin\app\logic\BaseLogic;
use plugin\admin\app\model\novel\NovelBusinessModel;
use plugin\admin\app\model\novel\NovelChapterModel;
use plugin\admin\app\model\novel\NovelSpreadModel;
use plugin\admin\app\model\plan\BackgroundMusicModel;
use plugin\admin\app\model\plan\PromotionPlanModel;
use plugin\admin\app\model\tencent\TimbreModel;
use support\Request;
use support\Response;

class MusicLogic extends BaseLogic
{
    protected static $instance;

    public function __construct()
    {
        $this->model = new BackgroundMusicModel();
    }

    public static function getInstance()
    {
        //        if(is_object(self::$instance)){
//            return self::$instance;
//        }

        return new self();
    }

    public function select(Request $request): Response
    {
        $field = $request->input('field');
        if($field==false){
            $request->inputSet('field','created_at');
            $request->inputSet('order','desc');
        }
        if($request->input('spread_type')==3){
            $request->inputSet('lang',['<>','中文']);
        }elseif($request->input('spread_type')==1){
            $request->inputSet('lang','中文');
        }

        $request->inputSet('isdel','0');
        return parent::select($request);
    }

    /**
     * 格式化下拉列表
     * @param $items
     * @return Response
     */
    protected function formatSelect($items): Response
    {
        $formatted_items = [];
        foreach ($items as $item) {
            $formatted_items[] = [
                'name' => ($item->name ?? $item->id).'('.$item->lang.')<a href="javascript:listen(\''.$item['music_url'].'\');">试听</a>',
                'value' => $item->id
            ];
        }
        return  json(['code' => 0, 'msg' => 'ok', 'data' => $formatted_items]);
    }

    public function insert(Request $request): Response
    {
        return parent::insert($request);
    }


    public function update(Request $request): Response
    {
        return parent::update($request);
    }

    public function delete(Request $request): Response
    {
        return parent::isDelete($request);
    }
}